import { RegionModel } from './home'
import { request } from '@/utils/request'
import { useUserStore } from '@/store/moudles/user'

//*--------------用户个人信息---------------
export interface UserInfo {
  url: string
  mid: number //用户mid
  name: string //昵称
  sex: string //性别
  face: string //头像链接
  sign: string //签名
  level: number //当前等级
  fans_badge: boolean //是否具有粉丝勋章
  nameplate: {
    //粉丝勋章信息
    nid: number //勋章ID
    name: string //勋章名称
    level: string //勋章等级
    image_small: string //勋章图片
  }
  top_photo: string //空间头图
  birthday: string //生日
}

//*--------------请求个人信息
export const reqUserInfo = (mid: number) =>
  request<UserInfo>({
    method: 'GET',
    url: '/space/acc/info',
    params: {
      mid,
    },
  })

//*--------------用户名片信息
export interface InfoCard {
  url: string
  mid: number //用户mid
  card: {
    fans: number
    formatFans: string
    friend: number
    formatFriends: string
  }
}
//*--------------请求关注数 粉丝数
export const reqUserCard = (mid: number) =>
  request<InfoCard>({
    method: 'GET',
    url: '/web-interface/card',
    params: {
      mid,
    },
  })

//*--------------UP主状态数据
export interface Upstatus {
  url: string
  mid: number //用户mid
  likes: number //获赞次数
  archive: {
    view: number //视频播放量
  }
  article: {
    view: number //专栏阅读量
  }
}
export const reqUpStatus = (mid: number) =>
  request<Upstatus>({
    method: 'GET',
    url: '/space/upstat',
    params: {
      mid,
    },
  })

//*--------------置顶视频------------
export interface TopVideo {
  tid: number
  aid: number //稿件avid
  cid: number //分p ID
  bvid: string //稿件avid
  pic: string //视频封面图片URL
  desc: string //视频简介
  duration: number //视频总时长
  stat: {
    view: number // 观看次数
    danmaku: number //弹幕数
  }
  title: string //稿件标题
  pubdate: number //发布时间
}

export const reqTopVideos = (vmid: number) =>
  request<TopVideo>({
    method: 'GET',
    url: '/space/top/arc',
    params: {
      vmid,
    },
  })

//*--------------投稿和我的视频------------
export interface Contribute {
  list: {
    //列表信息
    tlist: Tlist //投稿视频分区索引
    vlist: Vlist[] //投稿视频列表
  }
  page: {
    count: number //总计稿件数
    pn: number //当前页码
    ps: number //每页项数
  } //页面信息
  episodic_botton: {
    text: string //按钮文字
    uri: string //全部播放页URL
  } //"播放全部"按钮
}
//投稿视频分区索引
export interface Tlist {
  [key: string]: {
    tid: number //该分区名称
    count: number //投稿至该分区的视频数
    name: 'string' // 该分区tid
  }
}
//投稿视频对象
export interface Vlist {
  aid: number //稿件aid
  bvid: string //稿件aid
  pic: string //视频封面
  title: string //视频标题
  length: number //视频长度
  description: string //视频简介
  created: number //投稿时间
  play: number //视频播放数
  typeid: number //视频分区tid
}

export const reqContribute = (mid: number, pn: number) =>
  request<Contribute>({
    method: 'GET',
    url: '/space/arc/search',
    params: {
      mid,
      pn,
      ps: 8,
    },
  })

/* 查询用户投稿相簿预览
http://api.bilibili.com/x/space/album/index */
export interface userImage {
  count: number //总计图片数
  ctime: number //发布时间
  description: string //简介
  doc_id: number //相簿id
  like: number //点赞数
  pictures: {
    img_src: string //图片URL
    img_width: number //宽度
    img_height: number //高度
    img_size: number //大小
  }[]
  title: string //标题
  view: number //浏览数
}

/*  获取用户最近投币的视频明细
http://api.bilibili.com/x/space/coin/video
 */

export const reqRecentlyCoin = (vmid: number) =>
  request<RegionModel[]>({
    method: 'GET',
    url: '/space/coin/video',
    params: {
      vmid,
    },
  })

/* 查看用户空间公告
http://api.bilibili.com/x/space/notice
 */

export interface Notice {
  data: string //公告信息
  ttl: number
}
export const reqNotice = (mid: number) =>
  request<Notice>({
    method: 'GET',
    url: 'space/notice',
    params: {
      mid,
    },
  })

/*   查询用户频道列表
http://api.bilibili.com/x/space/channel/list */

export interface VideoList {
  count: number //总计频道数
  list: {
    cid: number //频道ID
    count: number //频道内涵视频数量
    cover: string //封面图片Url
    intro: string //简介
    mid: number //创建用户mid
    mtime: number //创建时间
    name: string //标题
    archives: TopVideo[] //小视频列表  自定义字段
  }[]
}

export const reqVideoList = (mid: number) =>
  request<VideoList>({
    method: 'GET',
    url: '/space/channel/list',
    params: {
      mid,
    },
  })

/* 查询用户频道中的视频
http://api.bilibili.com/x/space/channel/video */

export interface ChannelVideo {
  list: {
    cid: number //频道id
    count: number //频道内涵视频数
    cover: string //封面图片Url
    intro: string //简介
    mid: number //创建用户mid
    mtime: number //创建时间
    name: string //标题
    archives: TopVideo[]
  }
  page: {
    count: number //总计视频数
    num: number //当前页码
    size: number //每页项数
  }
}

export const reqChannelVideo = (mid: number, cid: number) =>
  request<ChannelVideo>({
    method: 'GET',
    url: '/space/channel/video',
    params: {
      mid,
      cid,
      ps: 6,
    },
  })

//获取动态页面请求
/* /dynamic_svr/v1/dynamic_svr/space_history */

export interface Dynamic {
  // bvid: string
  cards: {
    card: {
      //页面信息
      user?: {
        face: string
        uname: string
      }
      item?: {
        content: string
        timestamp: number
      }
      owner?: {
        face: string
        name: string
      }
      pubdate?: number
    }
    desc: {
      like: number //点赞
      repost: number //转发
    }
  }[]
  has_more: number
  next_offset: number //下一次的ID
}
/**
 *
 * @param visitor_uid
 * @param host_uid
 * @param offset_dynamic_id
 * @returns
 */
export const reqDynamic = (host_uid: number, offset_dynamic_id: number) =>
  request<Dynamic>({
    method: 'GET',
    url: '/dynamic_svr/v1/dynamic_svr/space_history',
    params: {
      visitor_uid: useUserStore().mid,
      host_uid,
      offset_dynamic_id,
      need_top: 1, //1
      platform: 'web', //web
    },
  })
